package chaoyue.study.feature;

import java.util.Optional;

public class OptionalTest {
    public static void main(String[] args) {
        Optional<String> optStr = Optional.empty();
        //System.out.println(optStr.get());

        Optional<String> optStr2 = Optional.ofNullable(null);
        //System.out.println(optStr2.get());

        Optional<String> optStr1 = Optional.of("hello");
        System.out.println(optStr1.get());
        // Optional的正确用法就是使用ifPresent来减少判断
        optStr1.ifPresent( s -> System.out.println("result is " + s));


    }
}
